<html>
<head><meta charset="utf-8"><title>finding disabled optional dependencies on a crate? · t-cargo · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/index.html">t-cargo</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/finding.20disabled.20optional.20dependencies.20on.20a.20crate.3F.html">finding disabled optional dependencies on a crate?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="226987071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/finding%20disabled%20optional%20dependencies%20on%20a%20crate%3F/near/226987071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/finding.20disabled.20optional.20dependencies.20on.20a.20crate.3F.html#226987071">(Feb 19 2021 at 16:17)</a>:</h4>
<p>Is there a way to see all the crates in my project that optionally depend on another crate, but don't currently? My concrete case is that I'm adding parking_lot to my project and I want other crates to use it as well. I know that Tokio has a feature flag to enable parking_lot, but I want to find other crates that have similar feature flags.</p>



<a name="226987617"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/finding%20disabled%20optional%20dependencies%20on%20a%20crate%3F/near/226987617" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/finding.20disabled.20optional.20dependencies.20on.20a.20crate.3F.html#226987617">(Feb 19 2021 at 16:20)</a>:</h4>
<p>I don't think there is. If it is ezzy to add for <code>cargo tree</code>, then I'd be for adding it. If that data is gone by the time <code>tree</code> runs, then this may need to be an outside tool.</p>



<a name="226990412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/finding%20disabled%20optional%20dependencies%20on%20a%20crate%3F/near/226990412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/finding.20disabled.20optional.20dependencies.20on.20a.20crate.3F.html#226990412">(Feb 19 2021 at 16:36)</a>:</h4>
<p>It's not super-easy, but you could do something like this:</p>
<ol>
<li>Run <code>cargo metadata</code>, and collect all packages that have a <code>"dependencies"</code> entry with the package in question with optional=true.</li>
<li>For each package that has one of those dependencies, see if the optional dependency was "activated" in the <code>"resolve"</code> graph.</li>
</ol>
<p>I imagine some clever person could do that in a single <code>jq</code> command.</p>



<a name="227009480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/finding%20disabled%20optional%20dependencies%20on%20a%20crate%3F/near/227009480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/finding.20disabled.20optional.20dependencies.20on.20a.20crate.3F.html#227009480">(Feb 19 2021 at 18:51)</a>:</h4>
<p>That'd be <span class="user-mention" data-user-id="158561">@Daniel Henry-Mantilla</span> :</p>
<div class="codehilite"><pre><span></span><code>cargo metadata --format-version 1 | jq -c &#39;.packages[] | select(
    .dependencies | any(
        (.name == &quot;parking_lot&quot;)
        and
        (.optional == true)
    )
) | .name&#39;
</code></pre></div>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>